package android.slc.appbase.vm;

import android.app.Application;
import android.slc.appbase.ui.vd.BaseAppVmBox;
import android.slc.appbase.utils.AppIntentUtils;
import android.slc.core.domain.VmBox;
import android.slc.corelifecycle.vm.RxViewModel;

import androidx.annotation.NonNull;

import java.io.Serializable;

/**
 * @author slc
 * @date 2020/3/12 13:40
 * @email sunlunchang@gmail.com
 */
public class AppBaseViewModel extends RxViewModel {

    public AppBaseViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    protected void registerVmBox(VmBox vmBox) {
        super.registerVmBox(vmBox);
        if (vmBox instanceof BaseAppVmBox) {
            BaseAppVmBox baseAppVmBox = (BaseAppVmBox) vmBox;
        }
    }

    /**
     * 填充返回结果
     *
     * @param data
     */
    public <T extends Serializable> void fillResult(T data) {
        fillResult(AppIntentUtils.getBundleByData(data));
    }

    /**
     * 填充返回结果并销毁
     *
     * @param data
     */
    public <T extends Serializable> void fillResultAndFinish(T data) {
        fillResultAndFinish(AppIntentUtils.getBundleByData(data));
    }

}
